package com.qfedu.dao.impl;

import com.qfedu.dao.UserDao;
import com.qfedu.entity.User;
import com.qfedu.utils.BaseDao;

import java.sql.SQLException;

public class UserDaoImpl extends BaseDao implements UserDao {
    @Override
    public User findUserByUserName(String username) throws SQLException {
        String sql = "select u_id as uid , u_name as username , u_password as upassword" +
                ", u_sex as usex , u_status as ustatus , u_code as code , u_email as email " +
                ", u_role as urole from user where u_name = ?";
        User user = queryBean(sql, User.class, username);
        return user;
    }

    @Override
    public int insertUser(User user) throws SQLException {
        String sql = "insert into user (u_name,u_password,u_sex,u_status," +
                "u_code,u_email,u_role) value (?,?,?,?,?,?,?)";
        int num = update(sql, user.getUsername(), user.getUpassword(), user.getUsex(), user.getUstatus(), user.getCode(), user.getEmail(), user.getUrole());
        return num;
    }

    @Override
    public int updateUserStatusByCode(String status, String code) throws SQLException {
        String sql = "update user set u_status = ? where u_code = ?";
        int num = update(sql, status, code);
        return num;
    }
}
